import {CurdHelper} from "@/main";
import {FormInput, FormInputNumber} from "@/zpkgs/hooks/form";
import {renderKeyValues} from "@example/views/datatable/mixins";


export function formatter(row, column, cellValue, index, { from } = {}) {
  let h = vueCompositionAPI.h
  return (<div>自然人</div>);
}

export function formatter2(row, column, cellValue, index, { from } = {}) {
  let h = vueCompositionAPI.h
  return (<div>{row.warningScoreBegin} -- {row.warningScoreEnd}</div>);
}

export function formatter3(row, column, cellValue, index, { from } = {}) {
  let h = vueCompositionAPI.h
  let style = {
    width: '40px',
    height: '20px',
    backgroundColor: cellValue
  }
  return (<div style={style}></div>);
}

export function onCurdInit(ctx) {
  // console.log('onCurdInit', ctx)
  // ctx.registerView('卡片2', GridView.name, GridView)
}

export async function onCurdDelete(ctx) {
  // console.log('onCurdDelete', ctx)
  await ctx.refs.searchTable.search()
  await ZY.sleep(10000)
}

export async function onCurdEdit(isEdit, ret, ctx) {
  await ctx.refs.searchTable.search()
  await ZY.sleep(10000)
}

let EditCom = CurdHelper.defineDialogView('EditCom1111111', {
  content: '111'
})

let DetailCom = CurdHelper.defineDetailView({renderKeyValues});
DetailCom.name = 'DetailCom'

export let obj = {
  defaultUrl: '/api/demo1/list',
  urlMap: {
    add: '/api/demo1/add',
    del: '/api/demo1/delete',
    edit: '/api/demo1/edit',
  },
  request: globalThis.Req,
  columnDefMap: {
    prop1: {
      formatter
    },
    prop2: {
      formatter: formatter2
    },
    color: {
      formatter: formatter3
    },
    content: {
      align: 'center'
    }
  },
  ext: {
    limit: 12
  },
  onCurdInit,
  onCurdEdit,
  onCurdDelete,
  EditCom,
  DetailCom
}

